from flask import Flask
from utils.ResultUtil import Response
import os, sys
from config.setting import SERVER_PORT
from router.test import test


BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, BASE_PATH)  # 将项目根路径临时加入环境变量，程序退出后失效

app = Flask(__name__)
app.register_blueprint(test)
app.config["JSON_AS_ASCII"] = False  # jsonify返回的中文正常显示

@app.route('/')
def hello_world():
    data = {
        "data": 'hello_world',
        'name': '测试'
    }
    return Response().success(data=data)


@app.before_request
def before_request_a():
    print('前置条件')


@app.after_request
def before_request_b(response):
    print('后置条件')
    return response


if __name__ == '__main__':
    # host为主机ip地址，port指定访问端口号，debug=True设置调试模式打开
    app.run(host="0.0.0.0", port=SERVER_PORT, debug=True)

